<template>
	<view>
		<bg-video></bg-video>
	</view>
</template>

<script>
	import storeInfo from "../mock/store.json";
	export default {
		data() {
			return {
				show: false,
				to: "author",
			}
		},
		onLoad: function(option) {
			if (option.code) {
				uni.navigateTo({
					url: "../pages/index?code=" + option.code + "&state="+option.state,
				});
			} else {
				if (option.to) {
					this.to = option.to;
				}
				this.getStoreInfo(storeInfo.appId, storeInfo.url);
			}
			
		},
		methods: {
			getStoreInfo: function(appId, url) {
				let self = this;
				this.http.get({
					url: "/store/info",
					param: {
						appId
					}
				}).then(function(res) {
					self.reload(appId, encodeURIComponent(url), res);
				});
			},
			reload: function(appId, redirecUri, res) {
				this.common.setAttribute("store", res);
				window.location.href =
					"https://open.weixin.qq.com/connect/oauth2/authorize?appid="
					+appId+"&redirect_uri="
					+redirecUri
					+"&scope=snsapi_userinfo&response_type=code&state="
					+res.storeId+"__"+this.to
					+"#wechat_redirect";
			}
		}
	}
</script>

<style scoped>
</style>
